﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CMS_GYM.Interface
{
    public partial class frmThongKeKhachHangTangTruong : Form
    {
        public frmThongKeKhachHangTangTruong()
        {
            InitializeComponent();
        }


        private void frmThongKeDoanhThu_Load(object sender, EventArgs e)
        {
            try
            {
                dtpNam.Value=DateTime.Now;
                KhoiTaoBieuDo();
                tbnXemKhachHangTangTruong_Click(null, null);
            }
            catch (Exception)
            { }
        }

        private void KhoiTaoBieuDo()
        {
            if (chartKhachHang.Series[0].Points.Count > 0)
            {
                chartKhachHang.Series[0].Points.Clear();
            }
            System.Windows.Forms.DataVisualization.Charting.DataPoint point = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
            point.IsValueShownAsLabel = false;
            point.XValue = 0;
            point.YValues = new double[] { 0 };
            point.Label = "Khách hàng tăng tưởng";
            chartKhachHang.Series[0].Points.Add(point);
        }

        private void tbnXemKhachHangTangTruong_Click(object sender, EventArgs e)
        {
            try
            {
                int Nam = dtpNam.Value.Year;
                DataTable Tabble = new clsKhachHangBUS().ThongKeSoLuongKhachHangTheoNamTheoCot(Nam);
                if (Tabble != null && Tabble.Rows.Count > 0 && Tabble.Columns.Count>0)
                {
                    chartKhachHang.Series[0].Points.Clear();
                    for (int i = 0; i < Tabble.Columns.Count; i++)
                    {
                        double DoanhThu = Tabble.Rows[0][i] == null || String.IsNullOrEmpty(Tabble.Rows[0][i].ToString()) ? 0 : Double.Parse(Tabble.Rows[0][i].ToString());
                        System.Windows.Forms.DataVisualization.Charting.DataPoint point = new System.Windows.Forms.DataVisualization.Charting.DataPoint();
                        point.IsValueShownAsLabel = true;
                        point.XValue = 0;
                        point.YValues = new double[] { DoanhThu };
                        point.Label = Tabble.Columns[i].ColumnName == null ? string.Empty : Tabble.Columns[i].ColumnName;
                        point.ToolTip = clsSupport.CurrencyNumber(DoanhThu.ToString());
                        point.LabelToolTip = clsSupport.CurrencyNumber(DoanhThu.ToString());
                        chartKhachHang.Series[0].Points.Add(point);
                    }
                }
                else
                {
                    KhoiTaoBieuDo();
                }

            }
            catch (Exception)
            { }

        }
    }
}
